package com.chixing.day17_reflect_thread.thread.synchronizedDemo;

public class Account {
    private String accName;
    private double accMoney;

    public double getAccMoney() {
        return accMoney;
    }

    public void setAccMoney(double accMoney) {
        this.accMoney = accMoney;
    }

    public String getAccName() {
        return accName;
    }

    public void setAccName(String accName) {
        this.accName = accName;
    }

    public Account(String accName, double accMoney) {
        this.accName = accName;
        this.accMoney = accMoney;
    }

    //synchronized : 当前线程 拥有account 对象的锁
    public  double depoist(double money){
        synchronized (this) {
            //模拟实际生活中 存款需要消耗的时间
            double temp = this.accMoney;
            temp += money;
            try {
                Thread.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            this.accMoney = temp;
            System.out.println(Thread.currentThread().getName() + "当前账户余额是" + this.accMoney);
        }
        return this.accMoney;
    }

    public synchronized double withdraw(double money){


        return this.accMoney;
    }
}
